<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "sys_agent".
 *
 * @property string $agent_uid
 * @property integer $point
 */
class SysAgent extends \yii\db\ActiveRecord
{
    public $errorMessage;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'sys_agent';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['point', 'director'], 'required'],
            [['point'], 'integer', 'min' => 0],

            /*[['agent_uid', 'point'], 'required'],
            [['agent_uid', 'point'], 'integer']*/
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'agent_uid' => '主键（来源用户基础表编号）',
            'point' => '授权点数',
            'director' => '负责人',
        ];
    }

    public function checkParam()
    {
        if (empty($this->director)) {
            $this->errorMessage = '请输入负责人！';
            return false;
        }
        if (empty($this->point)) {
            $this->errorMessage = '请输入授权点数！';
            return false;
        }
        if (!is_numeric($this->point) || $this->point < 0) {
            $this->errorMessage = '请输入大于或等于0的数字！';
            return false;
        }

        return true;
    }
}
